package com.dailyblue.java.spring.boot.jwt.controller;

import com.dailyblue.java.spring.boot.jwt.bean.User;
import com.dailyblue.java.spring.boot.jwt.exception.UserCodeNotFoundException;
import com.dailyblue.java.spring.boot.jwt.exception.UserPasswordErrorException;
import com.dailyblue.java.spring.boot.jwt.service.UserService;
import com.dailyblue.java.spring.boot.jwt.util.JsonResult;
import com.dailyblue.java.spring.boot.jwt.util.ResultTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public JsonResult login(User user) throws UserCodeNotFoundException, UserPasswordErrorException {
        log.info("用户开始登陆操作...");
        log.info("接收的参数是:{}", user);
        return userService.login(user);
    }

    // 这三个方法都是模拟的方法，需要用户登陆后才能访问
    @GetMapping("/a")
    public JsonResult a() {
        log.info("用户访问了a方法");
        return ResultTool.success("This is a method!");
    }

    @GetMapping("/b")
    public JsonResult b() {
        log.info("用户访问了b方法");
        return ResultTool.success("This is b method!");
    }

    @GetMapping("/c")
    public JsonResult c() {
        log.info("用户访问了c方法");
        return ResultTool.success("This is c method!");
    }
}
